package com.infore.authorityManagement.controller;


import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.infore.authorityManagement.entity.SysRole;
import com.infore.authorityManagement.enums.ResultStatus;
import com.infore.authorityManagement.repository.ISysRoleRepository;
import com.infore.authorityManagement.util.ResultEntity;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/test")
public class TestController {
    
    @Autowired
    private ISysRoleRepository sysRoleRepository;
	
	private static final Logger logger = LoggerFactory.getLogger(TestController.class);
	
	@ApiOperation(value = "测试接口")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "msg", value = "测试参数", paramType = "query", required = true, dataType = "String"),
	})
	@RequestMapping(value = "/test/msg", method = RequestMethod.GET )
	@ResponseBody
	public ResultEntity test(@RequestParam("msg")String msg) {
		ResultEntity resultEntity = new ResultEntity(ResultStatus.SUCCESS,"您输入的字符是：",msg);
		logger.info("1111111");
		return resultEntity;
	}
	
	@RequestMapping(value = "/test/add", method = RequestMethod.GET )
    @ResponseBody
    public ResultEntity add() {
        SysRole role = new SysRole();
        role.setCreateTime(new Timestamp(new Date().getTime()));
        role.setRoleName("测试");
        sysRoleRepository.saveAndFlush(role);
        
        return new ResultEntity(ResultStatus.SUCCESS,"您输入的字符是：",role);
    }
	
	@RequestMapping(value = "/test/query", method = RequestMethod.GET )
    @ResponseBody
    public ResultEntity query() {
        logger.info("1111111");
        List<SysRole> list = sysRoleRepository.findAll();
        
        return new ResultEntity(ResultStatus.SUCCESS,"您输入的字符是：").setDataList(list);
    }

}
